//
//  PullDownMenuCell.m
//  PigMarket
//
//  Created by mac on 2019/5/27.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "PullDownMenuCell.h"

@interface PullDownMenuCell ()
/**
 title
 */
@property (nonatomic , strong) UILabel *title;
/**
 icon
 */
@property (nonatomic , strong) UIImageView *icon;
/**
 selectImgView
 */
@property (nonatomic , strong) UIImageView *selectImgView;
@end
@implementation PullDownMenuCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifierID = @"identifierID";
    PullDownMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierID];
    if (cell == nil) {
        cell = [[PullDownMenuCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifierID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self.contentView addSubview:self.icon];
    [self.contentView addSubview:self.title];
    [self.contentView addSubview:self.selectImgView];
}

- (void)initLayout {
    // 布局子控件
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).offset(15);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(22);
    }];
    [self.selectImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(18, 18));
    }];
}

#pragma mark - getter and setter
- (void)setModel:(PullDownMenuModel *)model {
    _model = model;
    if (model.icon) {
        self.icon.image = [UIImage imageNamed:model.icon];
    } else {
        self.icon.hidden = YES;
    }
    
    self.title.text = model.title;
    if (model.isSelect) {
        self.selectImgView.image = [UIImage imageNamed:@"pay_default_selected"];
    } else {
        self.selectImgView.image = [UIImage imageNamed:@"pay_default"];
    }
}

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = [UIColor textBlackColor];
        _title.font = [UIFont middleFont];
    }
    return _title;
}
- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc] init];
    }
    return _icon;
}
- (UIImageView *)selectImgView {
    if (!_selectImgView) {
        _selectImgView = [[UIImageView alloc] init];
    }
    return _selectImgView;
}
@end
